package com.atguigu.phoenix;

import java.sql.*;

/**
 * Created by Smexy on 2022/9/4
 *
 *      JDBC怎么玩?
 *              ①获取Connection(url,driver(省略，根据url自动解析驱动),user,password)
 *              ②获取PrepareStatement
 *              ③填充占位符
 *              ④执行sql
 *              ⑤如果是读，返回一个ResultSet，遍历ResultSet获取结果
 *              ⑥关闭连接
 */
public class FatClient
{
    public static void main(String[] args) throws SQLException {

        // 1.添加链接   所有的hbase客户端，去连接hbase所使用的zk
        String url = "jdbc:phoenix:hadoop102:2181";

        // 2.获取连接
        Connection connection = DriverManager.getConnection(url);

        // 3.编译SQL语句
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");

        // 4.执行语句
        ResultSet resultSet = preparedStatement.executeQuery();

        // 5.输出结果
        while (resultSet.next()){
            System.out.println(resultSet.getString(1) + ":" + resultSet.getString(2) + ":" + resultSet.getString(3));
        }

        // 6.关闭资源
        connection.close();

    }
}
